<template>
  <el-card>
    <div class="cable">
      <div class="search">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="规格">
            <el-input
              v-model="formInline.specification"
              placeholder="请输入规格"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button class="addUser" @click="onSubmit">查询</el-button>
            <download-excel
              class="el-button"
              :data="tableData"
              :fields="json_fields"
              name="电缆统计表"
              >导出反馈汇总
            </download-excel>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        stripe
        :row-style="{ height: '60px', padding: '0 0' }"
      >
        <el-table-column prop="specification" label="规格" width="180">
        </el-table-column>
        <el-table-column prop="materials" label="材质" width="180">
        </el-table-column>
        <el-table-column prop="initM" label="入库米数（米）"> </el-table-column>
        <el-table-column prop="initW" label="入库重量（吨）"> </el-table-column>
        <el-table-column prop="lastW" label="出库重量（吨）神州仓库">
        </el-table-column>
        <el-table-column prop="date" label="反馈日期"> </el-table-column>
        <el-table-column prop="remark" label="备注"> </el-table-column>
      </el-table>
      <div class="block" style="float: right">
        <el-pagination
          layout="prev, pager, next"
          :total="tableData.length"
          :size="10"
        >
        </el-pagination>
      </div>
    </div>
  </el-card>
</template>

<script>
import utils from '../../utils/utils';
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        specification: ''
      },
      json_fields: {
        '规格': 'specification',
        '材质': 'materials',
        '入库米数（米）': 'initM',
        '入库吨数（吨）': 'initW',
        '出库吨数（吨）神州仓库': 'lastW',
        '反馈日期': 'date',
        '备注': 'remark'
      }
    };
  },
  methods: {
    onSubmit() {
      this.axios({
        url: 'http://localhost:8080/nan/getAllCable',
        params: { specification: this.formInline.specification }
      }).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.list;
        }
      });
    }
  },
  mounted() {
    this.axios({
      url: 'http://localhost:8080/nan/getAllCable'
    }).then(res => {
      if (res.data.code === 200) {
        this.tableData = res.data.data.list;

        this.tableData[0].date = utils.shiftDate(this.tableData[0].date);
        this.tableData[1].date = utils.shiftDate(this.tableData[1].date);
      }
    });
  }
};
</script>

<style></style>
